from utils.sql_util import select


class User:
    # 查询user表
    @staticmethod
    def select_user(values):
        sql = "select * from kr_user.t_user where phone = %s;" % values
        return select(sql=sql, values=values)

    # 查询account表
    @staticmethod
    def select_account(values):
        sql = "select * from kr_user.t_account where token = %s;" % values
        return select(sql=sql, values=values)


class LingDu:
    # 查询t_reader_affiliation表
    @staticmethod
    def select_affiliation(values):
        user_id = User.select_user(values=values)[0]["id"]
        print(user_id)
        sql = "select * from kr_distribution.t_reader_affiliation where user_id = %s;" % user_id
        res = select(sql=sql, values=user_id)
        return res

    # 查询t_reader_affiliation_record表
    @staticmethod
    def select_affiliation_record(values):
        # user_id = LingDu.select_user(values=values)[0]["id"]
        sql = "select * from kr_distribution.t_reader_affiliation_record where user_id = %s;" % values
        res = select(sql=sql, values=values)
        return res

    # 查询t_user_service_relation表
    @staticmethod
    def select_service_relation(values):
        # user_id = LingDu.select_user(values=values)[0]["id"]
        sql = "select * from kr_user.t_user_service_relation where user_id = %s;" % values
        res = select(sql=sql, values=values)
        return res

    # 查询t_user_service_relation_record表
    @staticmethod
    def select_service_relation_record(values):
        # user_id = LingDu.select_user(values=values)[0]["id"]
        sql = "select * from kr_user.t_user_service_relation_record where user_id = %s;" % values
        res = select(sql=sql, values=values)
        return res

    # 查询t_user_service_relation_record表
    @staticmethod
    def select_book(values):
        # user_id = LingDu.select_user(values=values)[0]["id"]
        sql = "select * from kr_goods.t_book where id in %s;" % values
        res = select(sql=sql, values=values)
        return res



